﻿$(function () {
    //setFocusOnFirst();
    applyjqcolors();
    $.datepicker.setDefaults($.datepicker.regional["ro"]);
    $('#mainMsg').dialog({ autoOpen: false, modal: true, height: 250, width: 700, resizable: false, buttons: { bine: function () { $(this).dialog('close'); } } });

});

function CKupdate() {
    for (instance in CKEDITOR.instances)
        CKEDITOR.instances[instance].updateElement();
    return true;
}

function tell(s, url) {
    if (url) $('#mainMsg').dialog({ buttons: { bine: function () { window.location = url; } } });
    $('#mainMsg').html(s).dialog('open');
}

function styleup() {
    var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
    $("select,fieldset,input:text,.ae-lookup-multidisplay,input[type='password'], textarea").addClass("ui-corner-all");
    $("input:text,.ae-lookup-multidisplay").addClass('ui-widget-content');
    $("input[type=submit]").addClass("abtn");
    $(".atbl thead").addClass("ui-state-default");

    $(".ae-lookup-list > li:even, .ae-lookup-list li:odd").removeClass('ui-widget-content ui-state-highlight');
    $(".ae-lookup-list > li:even").addClass("ui-widget-content");
    $(".ae-lookup-list > li:odd").addClass("ui-state-highlight");

    $(".atbl tbody tr:even, tbody tr:odd").removeClass("ui-widget-content ui-state-highlight");
    $(".atbl tbody tr:even").addClass("ui-widget-content");
    $(".atbl tbody tr:odd").addClass("ui-state-highlight");

    $('.ui-state-highlight a').css('color', $('.ui-state-default').css('color'));
    $ae.mybutton(".abtn");
    $ae.mybutton(".ae-lookup-morebtn");
    $(".validation-summary-errors").addClass('ui-state-error');

    $('.field-validation-error').each(function () {
        $(this).after('<div class="err" data-msg="' + $(this).html() + '"></div>').remove();
    });

    $(".err").each(function () {
        $(this).tooltip({ bodyHandler: function () { return $(this).data('msg'); }});
    });

    //after('err'+$(this).innerText+'aa').remove();
    //alert('style');
    if (!is_chrome)
        $(".input-validation-error").addClass('ui-state-error');

    $("[num]").keydown(function (event) {
        if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)) // 0-9 or numpad 0-9 
        { }
        else if (event.keyCode != 8 && event.keyCode != 46 && event.keyCode != 37 && event.keyCode != 39) // not esc, del, left or right 
        {
            event.preventDefault();
        }
    });
}

function applyjqcolors() {
    $.fx.speeds._default = 300;
    $(window).bind("resize", function (e) { $("#main-container").css("min-height", ($(window).height() - 120) + "px"); });
    $("#main-container").css("min-height", ($(window).height() - 120) + "px").addClass("ui-widget-content");
    $('#menu1 > li > ul  li').css('width', '100%');
    $('#menu1 > li > ul').addClass('ui-widget-content');
    styleup();
    $(document).ajaxComplete(styleup);
    $(document).bind("awesome", styleup);
    $(document).bind('dialogopen', function () { $('.ui-dialog').addClass('transparent'); });
}

function setFocusOnFirst() {
    $("input:text:visible:first").focus();
}